package com.wynne.ptldemo.service.serviceimpl;


import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import com.wynne.ptldemo.actor.ControlActor;
import com.wynne.ptldemo.pojo.PtlControl;
import com.wynne.ptldemo.repository.PtlControlRepository;
import com.wynne.ptldemo.util.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("mockDataService")
public class MockDataService {

    @Autowired
    private ActorSystem actorSystem;

    @Autowired
    private PtlControlRepository controlRepository;

    public void initControl() {
        List<PtlControl> ptlControls = controlRepository.findAll();
        for (PtlControl ptlControl : ptlControls) {
            ActorRef ref = actorSystem.actorOf(ControlActor.createDefinedControlActor(SpringContextUtil.getApplicationContext()), "control@" + ptlControl.getControlNo());
        }
    }
}
